document
  .querySelector('#btn-register')
  .addEventListener('click', async function () {
    const username = document.querySelector('[name="username"]').value
    const password = document.querySelector('[name="password"]').value

    if (username === '' || password === '') {
      return Toast.fail('账号和密码不能为空')
    } else if (username.length < 2 || username.length > 30) {
      return Toast.fail('账号应在2-30位之间')
    } else if (password.length < 6 || password.length > 30) {
      return Toast.fail('密码应在6-30位之间')
    }

    const { data } = await axios.post('/register', { username, password })
    console.log(data)
    Toast.success('注册成功')
    location.href = './login.html'
  })
